'''

'''
from typing import Optional

from c06_tree.utils import TreeNode


class Solution:

    # https://leetcode.cn/problems/minimum-depth-of-binary-tree/
    def minDepth(self, root: Optional[TreeNode]) -> int:
        def dfs(node):
            if not node: return 1e9
            if (not node.left) and (not node.right): return 1
            return min(dfs(node.left), dfs(node.right)) + 1
        return dfs(root) if root else 0

    # https://leetcode.cn/problems/maximum-depth-of-binary-tree/
    def maxDepth(self, root: Optional[TreeNode]) -> int:
        def dfs(node):
            if not node: return 0
            if (not node.left) and (not node.right): return 1
            return max(dfs(node.left), dfs(node.right)) + 1
        return dfs(root) if root else 0
